import 'package:base_lib/common/index.dart';
import 'package:base_lib/index.dart';
import 'package:flutter/material.dart';

class DiseasePageTest extends StatefulWidget {
  final Parameters parameters;

  DiseasePageTest(this.parameters);

  @override
  _WrapPageState createState() => _WrapPageState();
}

class _WrapPageState extends State<DiseasePageTest> {
  TextEditingController _editingController = TextEditingController();

  @override
  void dispose() {
    _editingController.dispose();
    super.dispose();
  }

  // 生成历史数据
  final List<String> _list = List<String>.generate(10, (i) => 'chip$i');

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text('WrapPage'),
        ),
        body: Wrap(
            spacing: 10,
            runSpacing: 5,
            children: _list.map<Widget>((s) {
              return (s == "chip1")
                  ? ActionChip(
                      onPressed: () {
                        _editingController.clear();
                        CustomDialog.customDialog(context,
                            child: Container(
                              color: Colors.white,
                              height: 60,
                              child: Row(
                                children: [
                                  10.hGapDp,
                                  Expanded(
                                    child: TextField(
                                      controller: _editingController,
                                    ),
                                  ),
                                  5.hGapDp,
                                  RaisedButton(
                                    color: Colors.blue.withAlpha(66),
                                    textColor: Colors.white,
                                    child: Text("确定"),
                                    onPressed: () {
                                      var string = _editingController.text;
                                      Navigator.pop(context);
                                      setState(() {
                                        _list.add(string);
                                      });
                                    },
                                  ),
                                  10.hGapDp,
                                ],
                              ),
                            ));
                      },
                      label: Text(s),
                      padding: EdgeInsets.all(5),
                      backgroundColor: Colors.grey.withAlpha(66),
                      shadowColor: Colors.blue,
                      elevation: 2,
                      pressElevation: 4,
                    )
                  : Chip(
                      label: Text('$s'),
                      avatar: Icon(Icons.person),
                      deleteIcon: Icon(
                        Icons.close,
                        color: Colors.red,
                      ),
                      onDeleted: () {
                        setState(() {
                          _list.remove(s); // 删除事件
                        });
                      },
                    );
            }).toList()));
  }
}
